using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using HappySprite.Simulation;

namespace HappySprite.Tests
{
    [TestClass]
    public class WorldTests
    {
        [TestMethod]
        public void OwnerTest()
        {
            World sim1 = new World();
            World sim2 = new World();
            Body item = new Body();

            // Item has null for owner
            Assert.IsNull(item.Owner);

            sim1.Add(item);

            // Item has sim1 as owner
            Assert.AreEqual(sim1, item.Owner);

            // sim1 Items collection yields item
            foreach (Body si in sim1.Items)
                Assert.AreEqual(item, si);

            sim2.Add(item);

            // Item has sim2 as owner
            Assert.AreEqual(sim2, item.Owner);

            // sim2 Items collection yields item
            foreach (Body si in sim2.Items)
                Assert.AreEqual(item, si);

            // sim1 Items collection is empty
            foreach (Body si in sim1.Items)
                Assert.Fail();
        }

        [TestMethod]
        public void VelocityTest()
        {
            World sim = new World();
            Body item = new Body();

            sim.Add(item);

            item.Velocity = Vector2.UnitX;

            // Run World 4 times with time span of 0.25 seconds each
            for (int i = 0; i < 4; i++)
                sim.Update(0.25f);

            // Assert x(t + dt) = v * dt
            Assert.AreEqual(Vector2.UnitX, item.Transform.Position);
        }
    }
}
